<template>
  <div class="form-grid-container">
    <span class="register-title">公司注册</span>
    <el-form ref="form" :model="form" label-width="120px">
      <el-form-item label="公司名称">
        <el-input v-model="form.name" style="width: 300px;"></el-input>
      </el-form-item>

      <el-form-item label="企业商标">
        <el-upload
            class="upload - demo"
            action="/api/file/uploadPicture"
            :on-success="handleSuccessbrand"
            :auto-upload="true">
          <el-button size="small" type="primary">点击上传</el-button>
        </el-upload>
        <img v-if="form.brand" :src="form.brand" style="width: 200px; height: 100px; object-fit: cover;">
      </el-form-item>


      <el-form-item label="营业执照">
        <el-upload
            class="upload - demo"
            action="/api/file/uploadPicture"
            :on-success="handleSuccesslicence"
            :auto-upload="true">
          <el-button size="small" type="primary">点击上传</el-button>
        </el-upload>
        <img v-if="form.license" :src="form.license" style="width: 200px; height: 100px; object-fit: cover;">
      </el-form-item>


      <el-form-item label="企业规模">
        <el-select v-model="form.size" placeholder="请选择">
          <el-option
              v-for="item in sizeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="公司介绍">
        <el-input type="textarea" v-model="form.description" style="width: 500px;"></el-input>
      </el-form-item>
      <el-form-item label="电子邮箱">
        <el-input v-model="form.email" style="width: 200px;"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立刻注册</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import axios from "axios";

export default {
  data() {
    return {
      form: {
        name: '',
        size:'',
        description:'',
        license:'',
        brand:'',
        email:''
      },
      sizeOptions: [{
        value: '不限',
        label: '不限'
      }, {
        value: '10-99',
        label: '10-99'
      }, {
        value: '100-499',
        label: '100-499'
      }, {
        value: '500-999',
        label: '500-999'
      }, {
        value: '1000以上',
        label: '1000以上'
      }],
    }
  },
  methods: {
    onSubmit() {
      axios.post("/api/company/register", {
        name: this.form.name,
        size: this.form.size,
        license: this.form.license,
        brand: this.form.brand,
        description: this.form.description,
        email: this.form.email,
        status: 0
      })
          .then(response => {
            console.log(response.data);
            this.$alert(`${this.form.name}公司的注册消息已经提交,待审核`, '提示', {
              confirmButtonText: '确定',
              callback: () => {
                location.reload(); // 点击确定按钮后刷新页面
              }
            });
          })
          .catch(error => {
            console.error(error);
          });
    },
    handleSuccesslicence(resp) {
      this.form.license=resp;
      console.log(this.form.license);
    },
    handleSuccessbrand(resp) {
      this.form.brand=resp;
      console.log(this.form.brand);
      console.log("666")
    },

  }
}
</script>
<style>

.form-grid-container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}
.register-title {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 20px;
}

</style>
